<template>
  <view>
    <uni-data-select v-model="val" :localdata="departments"></uni-data-select>
  </view>
</template>

<script setup lang="ts">
import api from '@/api'
import {computed, nextTick, ref} from 'vue'
import {onReady} from "@dcloudio/uni-app";

const props = defineProps({
  department: {
    type: String,
    default: ''
  }
})

const emits = defineEmits(['update:department'])
const departments = ref([])
onReady(() => {
  getDepartments()

})

const val = computed({
  get() {
    nextTick()
    return props.department
  },
  set(val) {
    emits('update:department', val)
  }
})


const getDepartments = () => {
  api.department.list().then(res => {
    if (res && res.data.code === 0) {
      let tmp = res.data.data
      Object.keys(tmp).forEach((key: string | number) => {
        departments.value.push({
          text: tmp[key].department,
          value: tmp[key].department
        })
      })
    }
  })

}
</script>

<style scoped>
</style>
